// author: Moser Michael (SWD09)
// date: 2011-12-14
// homework 4: race conditions

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h> 

void* calculate_int(void* ptr);

int main(int argc, char **argv)

{
     pthread_t thread1, thread2;
     int  i = 0;

     pthread_create( &thread1, NULL, calculate_int, &i);
     pthread_create( &thread2, NULL, calculate_int, &i);

 
     pthread_join( thread1, NULL);
     pthread_join( thread2, NULL); 

     printf("i: %d\n",i);

     exit(0);
}

void* calculate_int(void* ptr)
{

     int* j = (int*) ptr;  
     int k = 0;
     for (; k <10000000; k++)
       (*j)++;
}
